'''
@ problem
1 最后一个epoch的损失与完成训练后的评估损失浮动较大，不太正常。
'''
from build_graph import build_graph_2
from data import get_data, label_differ
from train import train, eval
import matplotlib.pyplot as plt

if __name__ == '__main__':

    # 1 搭建计算图与参数初始化
    graph = build_graph_2()
    graph.init_params()
    print(f'size of graph:{len(graph.nodes)}')

    # 2 读取训练数据
    data_in, data_label = get_data()
    print(data_in[0], data_label[0])

    # 3 数据集的离散程度
    avg, avg_loss = label_differ(data_label)
    print(f'avg {avg}, avg_loss {avg_loss}')

    # 3 评估
    loss1 = eval(graph=graph, inputs=data_in, labels=data_label, show=False, show_len=20)

    # 4 进行训练
    train(graph=graph, epoch=200, inputs=data_in, labels=data_label, lr=0.00005)

    # 5 评估
    loss2 = eval(graph=graph, inputs=data_in, labels=data_label, show=True, show_len=20)

    # 6 训练前后对比
    print(f'loss1:{loss1}, loss2:{loss2}')
